package com.pearl.jacksoncore.demo.databind.anno;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.pearl.jacksoncore.demo.pojo.Org;
import com.pearl.jacksoncore.demo.pojo.Role;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TD
 * @version 1.0
 * @date 2024/3/21
 */
//@JsonIgnoreProperties( value = "password",allowGetters = true)
//@JsonPropertyOrder({"org","roleList","birthdayDate","id"})
@JsonInclude(JsonInclude.Include.NON_NULL)
//@JsonRootName("userInfo")
public class UserInfo {

    // 用户ID
    private Long id;

    // 出生日期
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date birthdayDate;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime birthdayLocalDateTime;

    // 姓名
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonAlias("username")
    private String name;

    // 年龄
    @JsonProperty(value = "userAge")
    private Integer age;

    private String password;


    private String sex;

    private String phone;

    // 所属机构

    private Org org;

    @JsonKey
    private Map<String, String> map;
    // 角色列表

    private List<Role> roleList;
    // 省略 getter\setter..........

    GenderEnum gender;

    private Map<String, Object> collect = new HashMap<>();

    @JsonAnySetter
    public void setCollect(String key, Object value) {
        this.collect.put(key, value);
    }

    @JsonAnyGetter
    public Map<String, Object> getCollect() {
        return collect;
    }

    public GenderEnum getGender() {
        return gender;
    }

    public void setGender(GenderEnum gender) {
        this.gender = gender;
    }

    public String getPhone() {
        return phone;
    }

    @JsonSetter("mobilePhone")
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @JsonGetter("userSex")
    public String getSex() {
        return sex;
    }

    public Map<String, String> getMap() {
        return map;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Org getOrg() {
        return org;
    }

    public void setOrg(Org org) {
        this.org = org;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    @JsonGetter
    public Date getBirthdayDate() {
        return birthdayDate;
    }

    @JsonSetter
    public void setBirthdayDate(Date birthdayDate) {
        this.birthdayDate = birthdayDate;
    }

    public LocalDateTime getBirthdayLocalDateTime() {
        return birthdayLocalDateTime;
    }

    public void setBirthdayLocalDateTime(LocalDateTime birthdayLocalDateTime) {
        this.birthdayLocalDateTime = birthdayLocalDateTime;
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "id=" + id +
                ", birthdayDate=" + birthdayDate +
                ", sex=" + sex +
                ", birthdayDate=" + birthdayDate +
                ", phone=" + phone +
                ", password=" + password +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", org=" + org +
                ", roleList=" + roleList +
                '}';
    }
}
